package cn.com.czpb.client.module.personal.acticity;


import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import cn.com.czpb.client.R;
import cn.com.czpb.client.app.MToolBarActivity;
import cn.com.czpb.client.model.usercenter.EmptyEntity;
import cn.com.czpb.client.net.Factory;
import cn.com.czpb.client.utils.LogUtils;
import cn.com.czpb.client.utils.ParamUtils;
import cn.com.czpb.client.utils.TUtils;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

public class UserSuggestActivity extends MToolBarActivity {
    @BindView(R.id.email_user_suggest)
    EditText email_user_suggest;
    @BindView(R.id.content_user_suggest)
    EditText content_user_suggest;
    @BindView(R.id.ll_back)
    LinearLayout ll_back;




    @Override
    protected int setLayoutId() {
        return R.layout.activity_user_suggest;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        ll_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
        content_user_suggest.setHint("请填写您的宝贵建议");
    }



    @OnClick(R.id.ok)
    public void commit(View view) {
        String s_email = email_user_suggest.getText().toString().trim();
        String s_content = content_user_suggest.getText().toString().trim();
        if (s_content == null || "".equals(s_content)) {
            TUtils.toast("请输入反馈内容");
            return;
        }
        if (s_email == null || "".equals(s_email)) {
            TUtils.toast("请填写您的邮箱");
            return;
        }

        suggest(s_email, s_content);

    }

    private void suggest(String email, String content) {
        Map<String, String> map = new HashMap<>();
        map.put("siteid", "1");
        map.put("Email", email);
        map.put("content", content);
        Factory.provideHttpService().userSuggest(ParamUtils.getRequestParam(map))
                .onBackpressureBuffer()

                .subscribeOn(Schedulers.io())

                .filter(new Func1<EmptyEntity, Boolean>() {
                    @Override
                    public Boolean call(EmptyEntity emptyEntity) {
                        LogUtils.e( "call: "+emptyEntity.code);

                        return true;
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<EmptyEntity>() {
                    @Override
                    public void call(EmptyEntity emptyEntity) {
                        TUtils.toast(emptyEntity.msg);

                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LogUtils.e( "call: "+throwable.getMessage());

                    }
                });
    }
}
